package cn.lg.soar.core.util.easyexcel;

import cn.lg.soar.core.util.easyexcel.converters.*;
import com.alibaba.excel.EasyExcel;

import java.io.InputStream;
import java.util.List;

/**
 * @author luguoxiang 469599794@qq.com
 * @Date: 2025/4/8 11:46
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class ExcelImportUtils {

    private final static NumberToStringConverter NUMBER_TO_STRING_CONVERTER = new NumberToStringConverter();
    private final static NumberToBooleanConverter NUMBER_TO_BOOLEAN_CONVERTER = new NumberToBooleanConverter();
    private final static NumberToLocalDateConverter NUMBER_TO_LOCAL_DATE_CONVERTER = new NumberToLocalDateConverter();
    private final static NumberToLocalTimeConverter NUMBER_TO_LOCAL_TIME_CONVERTER = new NumberToLocalTimeConverter();
    private final static NumberToLocalDateTimeConverter NUMBER_TO_LOCAL_DATE_TIME_CONVERTER = new NumberToLocalDateTimeConverter();
    private final static BooleanConverter STRING_TO_BOOLEAN_CONVERTER = new BooleanConverter();

    public static <T>List<T> readSync(InputStream inputStream, Class<T> clazz) {
        return EasyExcel.read(inputStream)
                .registerConverter(NUMBER_TO_STRING_CONVERTER)
                .registerConverter(NUMBER_TO_BOOLEAN_CONVERTER)
                .registerConverter(NUMBER_TO_LOCAL_DATE_CONVERTER)
                .registerConverter(NUMBER_TO_LOCAL_TIME_CONVERTER)
                .registerConverter(NUMBER_TO_LOCAL_DATE_TIME_CONVERTER)
                .registerConverter(STRING_TO_BOOLEAN_CONVERTER)
                .head(clazz)
                .sheet()
                .doReadSync();
    }

}
